<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This file documents the use of the GNU compilers.

Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>RISC-V Options (Using the GNU Compiler Collection (GCC))</title>

<meta name="description" content="RISC-V Options (Using the GNU Compiler Collection (GCC))">
<meta name="keywords" content="RISC-V Options (Using the GNU Compiler Collection (GCC))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Indices.html" rel="index" title="Indices">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Submodel-Options.html" rel="up" title="Submodel Options">
<link href="RL78-Options.html" rel="next" title="RL78 Options">
<link href="PRU-Options.html" rel="prev" title="PRU Options">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
kbd.key {font-style: normal}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en_US">
<div class="subsection-level-extent" id="RISC_002dV-Options">
<div class="nav-panel">
<p>
Next: <a href="RL78-Options.html" accesskey="n" rel="next">RL78 Options</a>, Previous: <a href="PRU-Options.html" accesskey="p" rel="prev">PRU Options</a>, Up: <a href="Submodel-Options.html" accesskey="u" rel="up">Machine-Dependent Options</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="RISC_002dV-Options-1"><span>3.19.40 RISC-V Options<a class="copiable-link" href="#RISC_002dV-Options-1"> &para;</a></span></h4>
<a class="index-entry-id" id="index-RISC_002dV-Options"></a>

<p>These command-line options are defined for RISC-V targets:
</p>
<dl class="table">
<dt><a id="index-mbranch_002dcost-4"></a><span><code class="code">-mbranch-cost=<var class="var">n</var></code><a class="copiable-link" href="#index-mbranch_002dcost-4"> &para;</a></span></dt>
<dd><p>Set the cost of branches to roughly <var class="var">n</var> instructions.
</p>
</dd>
<dt><a id="index-plt"></a><span><code class="code">-mplt</code><a class="copiable-link" href="#index-plt"> &para;</a></span></dt>
<dt><code class="code">-mno-plt</code></dt>
<dd><p>When generating PIC code, do or don&rsquo;t allow the use of PLTs. Ignored for
non-PIC.  The default is <samp class="option">-mplt</samp>.
</p>
</dd>
<dt><a id="index-mabi-4"></a><span><code class="code">-mabi=<var class="var">ABI-string</var></code><a class="copiable-link" href="#index-mabi-4"> &para;</a></span></dt>
<dd><p>Specify integer and floating-point calling convention.  <var class="var">ABI-string</var>
contains two parts: the size of integer types and the registers used for
floating-point types.  For example &lsquo;<samp class="samp">-march=rv64ifd -mabi=lp64d</samp>&rsquo; means that
&lsquo;<samp class="samp">long</samp>&rsquo; and pointers are 64-bit (implicitly defining &lsquo;<samp class="samp">int</samp>&rsquo; to be
32-bit), and that floating-point values up to 64 bits wide are passed in F
registers.  Contrast this with &lsquo;<samp class="samp">-march=rv64ifd -mabi=lp64f</samp>&rsquo;, which still
allows the compiler to generate code that uses the F and D extensions but only
allows floating-point values up to 32 bits long to be passed in registers; or
&lsquo;<samp class="samp">-march=rv64ifd -mabi=lp64</samp>&rsquo;, in which no floating-point arguments will be
passed in registers.
</p>
<p>The default for this argument is system dependent, users who want a specific
calling convention should specify one explicitly.  The valid calling
conventions are: &lsquo;<samp class="samp">ilp32</samp>&rsquo;, &lsquo;<samp class="samp">ilp32f</samp>&rsquo;, &lsquo;<samp class="samp">ilp32d</samp>&rsquo;, &lsquo;<samp class="samp">lp64</samp>&rsquo;,
&lsquo;<samp class="samp">lp64f</samp>&rsquo;, and &lsquo;<samp class="samp">lp64d</samp>&rsquo;.  Some calling conventions are impossible to
implement on some ISAs: for example, &lsquo;<samp class="samp">-march=rv32if -mabi=ilp32d</samp>&rsquo; is
invalid because the ABI requires 64-bit values be passed in F registers, but F
registers are only 32 bits wide.  There is also the &lsquo;<samp class="samp">ilp32e</samp>&rsquo; ABI that can
only be used with the &lsquo;<samp class="samp">rv32e</samp>&rsquo; architecture.  This ABI is not well
specified at present, and is subject to change.
</p>
</dd>
<dt><a id="index-mfdiv"></a><span><code class="code">-mfdiv</code><a class="copiable-link" href="#index-mfdiv"> &para;</a></span></dt>
<dt><code class="code">-mno-fdiv</code></dt>
<dd><p>Do or don&rsquo;t use hardware floating-point divide and square root instructions.
This requires the F or D extensions for floating-point registers.  The default
is to use them if the specified architecture has these instructions.
</p>
</dd>
<dt><a id="index-mdiv-3"></a><span><code class="code">-mdiv</code><a class="copiable-link" href="#index-mdiv-3"> &para;</a></span></dt>
<dt><code class="code">-mno-div</code></dt>
<dd><p>Do or don&rsquo;t use hardware instructions for integer division.  This requires the
M extension.  The default is to use them if the specified architecture has
these instructions.
</p>
</dd>
<dt><a id="index-misa_002dspec"></a><span><code class="code">-misa-spec=<var class="var">ISA-spec-string</var></code><a class="copiable-link" href="#index-misa_002dspec"> &para;</a></span></dt>
<dd><p>Specify the version of the RISC-V Unprivileged (formerly User-Level)
ISA specification to produce code conforming to.  The possibilities
for <var class="var">ISA-spec-string</var> are:
</p><dl class="table">
<dt><code class="code">2.2</code></dt>
<dd><p>Produce code conforming to version 2.2.
</p></dd>
<dt><code class="code">20190608</code></dt>
<dd><p>Produce code conforming to version 20190608.
</p></dd>
<dt><code class="code">20191213</code></dt>
<dd><p>Produce code conforming to version 20191213.
</p></dd>
</dl>
<p>The default is <samp class="option">-misa-spec=20191213</samp> unless GCC has been configured
with <samp class="option">--with-isa-spec=</samp> specifying a different default version.
</p>
</dd>
<dt><a id="index-march-14"></a><span><code class="code">-march=<var class="var">ISA-string</var></code><a class="copiable-link" href="#index-march-14"> &para;</a></span></dt>
<dd><p>Generate code for given RISC-V ISA (e.g. &lsquo;<samp class="samp">rv64im</samp>&rsquo;).  ISA strings must be
lower-case.  Examples include &lsquo;<samp class="samp">rv64i</samp>&rsquo;, &lsquo;<samp class="samp">rv32g</samp>&rsquo;, &lsquo;<samp class="samp">rv32e</samp>&rsquo;, and
&lsquo;<samp class="samp">rv32imaf</samp>&rsquo;.
</p>
<p>When <samp class="option">-march=</samp> is not specified, use the setting from <samp class="option">-mcpu</samp>.
</p>
<p>If both <samp class="option">-march</samp> and <samp class="option">-mcpu=</samp> are not specified, the default for
this argument is system dependent, users who want a specific architecture
extensions should specify one explicitly.
</p>
</dd>
<dt><a id="index-mcpu-8"></a><span><code class="code">-mcpu=<var class="var">processor-string</var></code><a class="copiable-link" href="#index-mcpu-8"> &para;</a></span></dt>
<dd><p>Use architecture of and optimize the output for the given processor, specified
by particular CPU name.
Permissible values for this option are: &lsquo;<samp class="samp">sifive-e20</samp>&rsquo;, &lsquo;<samp class="samp">sifive-e21</samp>&rsquo;,
&lsquo;<samp class="samp">sifive-e24</samp>&rsquo;, &lsquo;<samp class="samp">sifive-e31</samp>&rsquo;, &lsquo;<samp class="samp">sifive-e34</samp>&rsquo;, &lsquo;<samp class="samp">sifive-e76</samp>&rsquo;,
&lsquo;<samp class="samp">sifive-s21</samp>&rsquo;, &lsquo;<samp class="samp">sifive-s51</samp>&rsquo;, &lsquo;<samp class="samp">sifive-s54</samp>&rsquo;, &lsquo;<samp class="samp">sifive-s76</samp>&rsquo;,
&lsquo;<samp class="samp">sifive-u54</samp>&rsquo;, and &lsquo;<samp class="samp">sifive-u74</samp>&rsquo;.
</p>
</dd>
<dt><a id="index-mtune-12"></a><span><code class="code">-mtune=<var class="var">processor-string</var></code><a class="copiable-link" href="#index-mtune-12"> &para;</a></span></dt>
<dd><p>Optimize the output for the given processor, specified by microarchitecture or
particular CPU name.  Permissible values for this option are: &lsquo;<samp class="samp">rocket</samp>&rsquo;,
&lsquo;<samp class="samp">sifive-3-series</samp>&rsquo;, &lsquo;<samp class="samp">sifive-5-series</samp>&rsquo;, &lsquo;<samp class="samp">sifive-7-series</samp>&rsquo;,
&lsquo;<samp class="samp">thead-c906</samp>&rsquo;, &lsquo;<samp class="samp">size</samp>&rsquo;, and all valid options for <samp class="option">-mcpu=</samp>.
</p>
<p>When <samp class="option">-mtune=</samp> is not specified, use the setting from <samp class="option">-mcpu</samp>,
the default is &lsquo;<samp class="samp">rocket</samp>&rsquo; if both are not specified.
</p>
<p>The &lsquo;<samp class="samp">size</samp>&rsquo; choice is not intended for use by end-users.  This is used
when <samp class="option">-Os</samp> is specified.  It overrides the instruction cost info
provided by <samp class="option">-mtune=</samp>, but does not override the pipeline info.  This
helps reduce code size while still giving good performance.
</p>
</dd>
<dt><a id="index-mpreferred_002dstack_002dboundary"></a><span><code class="code">-mpreferred-stack-boundary=<var class="var">num</var></code><a class="copiable-link" href="#index-mpreferred_002dstack_002dboundary"> &para;</a></span></dt>
<dd><p>Attempt to keep the stack boundary aligned to a 2 raised to <var class="var">num</var>
byte boundary.  If <samp class="option">-mpreferred-stack-boundary</samp> is not specified,
the default is 4 (16 bytes or 128-bits).
</p>
<p><strong class="strong">Warning:</strong> If you use this switch, then you must build all modules with
the same value, including any libraries.  This includes the system libraries
and startup modules.
</p>
</dd>
<dt><a id="index-msmall_002ddata_002dlimit-1"></a><span><code class="code">-msmall-data-limit=<var class="var">n</var></code><a class="copiable-link" href="#index-msmall_002ddata_002dlimit-1"> &para;</a></span></dt>
<dd><p>Put global and static data smaller than <var class="var">n</var> bytes into a special section
(on some targets).
</p>
</dd>
<dt><a id="index-msave_002drestore"></a><span><code class="code">-msave-restore</code><a class="copiable-link" href="#index-msave_002drestore"> &para;</a></span></dt>
<dt><code class="code">-mno-save-restore</code></dt>
<dd><p>Do or don&rsquo;t use smaller but slower prologue and epilogue code that uses
library function calls.  The default is to use fast inline prologues and
epilogues.
</p>
</dd>
<dt><a id="index-minline_002datomics"></a><span><code class="code">-minline-atomics</code><a class="copiable-link" href="#index-minline_002datomics"> &para;</a></span></dt>
<dt><code class="code">-mno-inline-atomics</code></dt>
<dd><p>Do or don&rsquo;t use smaller but slower subword atomic emulation code that uses
libatomic function calls.  The default is to use fast inline subword atomics
that do not require libatomic.
</p>
</dd>
<dt><a id="index-mshorten_002dmemrefs"></a><span><code class="code">-mshorten-memrefs</code><a class="copiable-link" href="#index-mshorten_002dmemrefs"> &para;</a></span></dt>
<dt><code class="code">-mno-shorten-memrefs</code></dt>
<dd><p>Do or do not attempt to make more use of compressed load/store instructions by
replacing a load/store of &rsquo;base register + large offset&rsquo; with a new load/store
of &rsquo;new base + small offset&rsquo;.  If the new base gets stored in a compressed
register, then the new load/store can be compressed.  Currently targets 32-bit
integer load/stores only.
</p>
</dd>
<dt><a id="index-mstrict_002dalign-3"></a><span><code class="code">-mstrict-align</code><a class="copiable-link" href="#index-mstrict_002dalign-3"> &para;</a></span></dt>
<dt><code class="code">-mno-strict-align</code></dt>
<dd><p>Do not or do generate unaligned memory accesses.  The default is set depending
on whether the processor we are optimizing for supports fast unaligned access
or not.
</p>
</dd>
<dt><a id="index-mcmodel_003dmedlow"></a><span><code class="code">-mcmodel=medlow</code><a class="copiable-link" href="#index-mcmodel_003dmedlow"> &para;</a></span></dt>
<dd><p>Generate code for the medium-low code model. The program and its statically
defined symbols must lie within a single 2 GiB address range and must lie
between absolute addresses &minus;2 GiB and +2 GiB. Programs can be
statically or dynamically linked. This is the default code model.
</p>
</dd>
<dt><a id="index-mcmodel_003dmedany"></a><span><code class="code">-mcmodel=medany</code><a class="copiable-link" href="#index-mcmodel_003dmedany"> &para;</a></span></dt>
<dd><p>Generate code for the medium-any code model. The program and its statically
defined symbols must be within any single 2 GiB address range. Programs can be
statically or dynamically linked.
</p>
<p>The code generated by the medium-any code model is position-independent, but is
not guaranteed to function correctly when linked into position-independent
executables or libraries.
</p>
</dd>
<dt><code class="code">-mexplicit-relocs</code></dt>
<dt><code class="code">-mno-exlicit-relocs</code></dt>
<dd><p>Use or do not use assembler relocation operators when dealing with symbolic
addresses.  The alternative is to use assembler macros instead, which may
limit optimization.
</p>
</dd>
<dt><a id="index-mrelax-5"></a><span><code class="code">-mrelax</code><a class="copiable-link" href="#index-mrelax-5"> &para;</a></span></dt>
<dt><code class="code">-mno-relax</code></dt>
<dd><p>Take advantage of linker relaxations to reduce the number of instructions
required to materialize symbol addresses. The default is to take advantage of
linker relaxations.
</p>
</dd>
<dt><a id="index-mriscv_002dattribute"></a><span><code class="code">-mriscv-attribute</code><a class="copiable-link" href="#index-mriscv_002dattribute"> &para;</a></span></dt>
<dt><code class="code">-mno-riscv-attribute</code></dt>
<dd><p>Emit (do not emit) RISC-V attribute to record extra information into ELF
objects.  This feature requires at least binutils 2.32.
</p>
</dd>
<dt><a id="index-mcsr_002dcheck"></a><span><code class="code">-mcsr-check</code><a class="copiable-link" href="#index-mcsr_002dcheck"> &para;</a></span></dt>
<dt><code class="code">-mno-csr-check</code></dt>
<dd><p>Enables or disables the CSR checking.
</p>
</dd>
<dt><a id="index-malign_002ddata"></a><span><code class="code">-malign-data=<var class="var">type</var></code><a class="copiable-link" href="#index-malign_002ddata"> &para;</a></span></dt>
<dd><p>Control how GCC aligns variables and constants of array, structure, or union
types.  Supported values for <var class="var">type</var> are &lsquo;<samp class="samp">xlen</samp>&rsquo; which uses x register
width as the alignment value, and &lsquo;<samp class="samp">natural</samp>&rsquo; which uses natural alignment.
&lsquo;<samp class="samp">xlen</samp>&rsquo; is the default.
</p>
</dd>
<dt><a id="index-mbig_002dendian-10"></a><span><code class="code">-mbig-endian</code><a class="copiable-link" href="#index-mbig_002dendian-10"> &para;</a></span></dt>
<dd><p>Generate big-endian code.  This is the default when GCC is configured for a
&lsquo;<samp class="samp">riscv64be-*-*</samp>&rsquo; or &lsquo;<samp class="samp">riscv32be-*-*</samp>&rsquo; target.
</p>
</dd>
<dt><a id="index-mlittle_002dendian-10"></a><span><code class="code">-mlittle-endian</code><a class="copiable-link" href="#index-mlittle_002dendian-10"> &para;</a></span></dt>
<dd><p>Generate little-endian code.  This is the default when GCC is configured for a
&lsquo;<samp class="samp">riscv64-*-*</samp>&rsquo; or &lsquo;<samp class="samp">riscv32-*-*</samp>&rsquo; but not a &lsquo;<samp class="samp">riscv64be-*-*</samp>&rsquo; or
&lsquo;<samp class="samp">riscv32be-*-*</samp>&rsquo; target.
</p>
</dd>
<dt><a class="index-entry-id" id="index-mstack_002dprotector_002dguard_002dreg-1"></a>
<a class="index-entry-id" id="index-mstack_002dprotector_002dguard_002doffset-2"></a>
<a id="index-mstack_002dprotector_002dguard-2"></a><span><code class="code">-mstack-protector-guard=<var class="var">guard</var></code><a class="copiable-link" href="#index-mstack_002dprotector_002dguard-2"> &para;</a></span></dt>
<dt><code class="code">-mstack-protector-guard-reg=<var class="var">reg</var></code></dt>
<dt><code class="code">-mstack-protector-guard-offset=<var class="var">offset</var></code></dt>
<dd><p>Generate stack protection code using canary at <var class="var">guard</var>.  Supported
locations are &lsquo;<samp class="samp">global</samp>&rsquo; for a global canary or &lsquo;<samp class="samp">tls</samp>&rsquo; for per-thread
canary in the TLS block.
</p>
<p>With the latter choice the options
<samp class="option">-mstack-protector-guard-reg=<var class="var">reg</var></samp> and
<samp class="option">-mstack-protector-guard-offset=<var class="var">offset</var></samp> furthermore specify
which register to use as base register for reading the canary,
and from what offset from that base register. There is no default
register or offset as this is entirely for use within the Linux
kernel.
</p></dd>
</dl>

</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="RL78-Options.html">RL78 Options</a>, Previous: <a href="PRU-Options.html">PRU Options</a>, Up: <a href="Submodel-Options.html">Machine-Dependent Options</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
